﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace 计科201518
{
    public partial class 简易计算器 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        static string num1 = "0", num2 = "0", total = "", sign = "";

        protected void count()
        {
            num2 = txtDisplay.Text;
            if (num2 == " ")
            { num2 = "0"; }
            switch (sign)
            {
                case "+":
                    txtDisplay.Text = (int.Parse(num1) + int.Parse(num2)).ToString();
                    num1 = "0"; num2 = "0"; total = " "; sign = " "; break;
                case "-":
                    txtDisplay.Text = (int.Parse(num1) - int.Parse(num2)).ToString();
                    num1 = "0"; num2 = "0"; total = " "; sign = " "; break;
            }
        }

        protected void btnadd_Click(object sender, EventArgs e)
        {
            if (sign.Length == 1)
            {
                count();
                num1 = txtDisplay.Text;
                sign = "+";
            }
            else
            {
                num1 = txtDisplay.Text;
                txtDisplay.Text = " ";
                total = " ";
                sign = "+";
            }
        }

        protected void btnsubtract_Click(object sender, EventArgs e)
        {

            if (sign.Length == 1)
            {
                count();
                num1 = txtDisplay.Text;
                sign = "-";
            }
            else
            {
                num1 = txtDisplay.Text;
                txtDisplay.Text = " ";
                total = " ";
                sign = "-";
            }
        }

        protected void btnequal_Click(object sender, EventArgs e)
        {
            count();
        }

        protected void btntree_Click(object sender, EventArgs e)
        {
            total += "3";
            txtDisplay.Text = total;
        }

        protected void btntwo_Click(object sender, EventArgs e)
        {
            total += "2";
            txtDisplay.Text = total;
        }

        protected void btnone_Click(object sender, EventArgs e)
        {
            total += "1";
            txtDisplay.Text = total;
        }
    }
}
